//
//  BankTableViewCell.m
//  Findif
//
//  Created by Mac on 2018/11/27.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "BankTableViewCell.h"

@interface BankTableViewCell ()

@property (nonatomic, weak)UIImageView * backImageView;
@property (nonatomic, weak)UILabel * backLabel;
@property (nonatomic, weak)UILabel * smallLabel;
@property (nonatomic, weak)UILabel * cardLabel;

@end

@implementation BankTableViewCell

- (void)setModel:(BankModel *)model{
    
    _model = model;
    
    NSString * card = model.bank_card_no;
    if (card.length == 16) {
        
        NSString * showCardNo = [card substringFromIndex:12];
        self.cardLabel.text = [NSString stringWithFormat:@"尾号%@",showCardNo];
    }else{
        
        NSString * showCardNo = [card substringFromIndex:15];
        self.cardLabel.text = [NSString stringWithFormat:@"尾号%@",showCardNo];
    }
    
    self.backLabel.text = model.belongs_to_bank;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = ZRWhiteColor;
    
    UIImageView * backImageView = [UIImageView new];
    NSUInteger r = arc4random_uniform(3) + 1;
    NSString * imgName = [NSString stringWithFormat:@"银行卡%lu",(unsigned long)r];
    backImageView.image = [UIImage imageNamed:imgName];
    
    self.backImageView = backImageView;
    
    [self.contentView addSubview:self.backImageView];
    
    UILabel * bankLabel = [UILabel new];
    
    bankLabel.textColor = ZRWhiteColor;
    bankLabel.font = [UIFont boldSystemFontOfSize:17 * SCREENH6];
    bankLabel.text = @"----";
    
    self.backLabel = bankLabel;
    
    [self.backImageView addSubview:self.backLabel];
    
    UILabel * smallLabel = [UILabel new];
    
    smallLabel.textColor = ColorWithRGB(0xF4F5F6);
    smallLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    smallLabel.text = @"储蓄卡";
    
    self.smallLabel = smallLabel;
    
    [self.backImageView addSubview:self.smallLabel];
    
    
    UILabel * cardLabel = [UILabel new];
    
    cardLabel.textColor = ZRWhiteColor;
    cardLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    cardLabel.text = @"----";
    
    self.cardLabel = cardLabel;
    
    [self.backImageView addSubview:self.cardLabel];
}

-(void)layoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(315 * SCREENH6);
        make.height.mas_equalTo(115 * SCREENH6);
        make.leading.mas_equalTo(25 * SCREENH6);
    }];
    
    [self.backLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backImageView).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.backImageView).offset(20 * SCREENH6);
    }];
    
    [self.smallLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.backLabel);
        make.leading.mas_equalTo(self.backLabel.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.cardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backLabel);
        make.top.mas_equalTo(self.backLabel.mas_bottom).offset(20 * SCREENH6);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
